package com.example.myapplication.frament;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.DynastyDialog;
import com.example.myapplication.R;
import com.example.myapplication.adapter.DynastyAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FragmentDynasty extends Fragment {
    @BindView(R.id.dynasty_recyclerView)
    RecyclerView dynastyRecyclerView;
    private List<String> list;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getContext(), R.layout.fragment_dynasty, null);
        ButterKnife.bind(this , view);
        initData();
        return view;
    }
    private void initData() {
        list = new ArrayList<>();
        list.add("夏");
        list.add("商");
        list.add("周");
        list.add("秦");
        list.add("汉");
        list.add("魏");
        list.add("蜀");
        list.add("吴");
        list.add("晋");
        list.add("宋");
        list.add("齐");
        list.add("梁");
        list.add("陈");
        list.add("隋");
        list.add("唐");
        list.add("宋");
        list.add("元");
        list.add("明");
        list.add("清");
        setAdapter();
    }
    private void setAdapter(){
        GridLayoutManager manager = new GridLayoutManager(getContext() , 3);
        dynastyRecyclerView.setLayoutManager(manager);
        DynastyAdapter adapter = new DynastyAdapter(list , getActivity().getSupportFragmentManager() , getContext() , getActivity() , new DynastyAdapter.OnItemClickListener() {
            @Override
            public void onClick(int position) {
                DynastyDialog dynastyDialog = new DynastyDialog();
                dynastyDialog.setContent(list.get(position));
                dynastyDialog.showNow(getActivity().getSupportFragmentManager() , "dialog");
            }
        });
        dynastyRecyclerView.setAdapter(adapter);
    }

}
